package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ChatRole;
import com.ruoyi.system.service.IChatRoleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * gptRoleController
 * 
 * @author ruoyi
 * @date 2024-04-28
 */
@RestController
@RequestMapping("/system/gptRole")
public class ChatRoleController extends BaseController
{
    @Autowired
    private IChatRoleService chatRoleService;

    /**
     * 查询gptRole列表
     */
    @PreAuthorize("@ss.hasPermi('system:gptRole:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChatRole chatRole)
    {
        startPage();
        List<ChatRole> list = chatRoleService.selectChatRoleList(chatRole);
        return getDataTable(list);
    }

    /**
     * 导出gptRole列表
     */
    @PreAuthorize("@ss.hasPermi('system:gptRole:export')")
    @Log(title = "gptRole", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChatRole chatRole)
    {
        List<ChatRole> list = chatRoleService.selectChatRoleList(chatRole);
        ExcelUtil<ChatRole> util = new ExcelUtil<ChatRole>(ChatRole.class);
        util.exportExcel(response, list, "gptRole数据");
    }

    /**
     * 获取gptRole详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:gptRole:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(chatRoleService.selectChatRoleById(id));
    }

    /**
     * 新增gptRole
     */
    @PreAuthorize("@ss.hasPermi('system:gptRole:add')")
    @Log(title = "gptRole", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChatRole chatRole)
    {
        return toAjax(chatRoleService.insertChatRole(chatRole));
    }

    /**
     * 修改gptRole
     */
    @PreAuthorize("@ss.hasPermi('system:gptRole:edit')")
    @Log(title = "gptRole", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChatRole chatRole)
    {
        return toAjax(chatRoleService.updateChatRole(chatRole));
    }

    /**
     * 删除gptRole
     */
    @PreAuthorize("@ss.hasPermi('system:gptRole:remove')")
    @Log(title = "gptRole", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(chatRoleService.deleteChatRoleByIds(ids));
    }
}
